home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / exec / _ExecArgs.c next >
Encoding:
C/C++ Source or Header  |  1988-07-29  |  1.9 KB  |  71 lines

  1. /* 
  2.  * _ExecArgs.c --
  3.  *
  4.  *    Source code for the _ExecArgs library utility procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: _ExecArgs.c,v 1.2 88/07/28 17:49:57 ouster Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <varargs.h>
  21.  
  22. /*
  23.  * Library imports:
  24.  */
  25.  
  26. extern char *malloc();
  27.  
  28.  
  29. /*
  30.  *----------------------------------------------------------------------
  31.  *
  32.  * _ExecArgs --
  33.  *
  34.  *    Collect an argument list, as passed to execl or execle, into
  35.  *    a dynamically-allocated array.
  36.  *
  37.  * Results:
  38.  *    The return value is a pointer to an array, dynamically
  39.  *    allocated, that contains the argv values pointed to by
  40.  *    args.  Args is updated so that the next va_arg will return
  41.  *    the argument just after the terminating 0 in the argv
  42.  *    list.  It is the caller's responsibility to free the
  43.  *    return value if that is desired.
  44.  *
  45.  * Side effects:
  46.  *    None.
  47.  *
  48.  *----------------------------------------------------------------------
  49.  */
  50.  
  51. char **
  52. _ExecArgs(args)
  53.     va_list *args;        /* Pointer to arguments containing a variable-
  54.                  * length collection of argv values, with
  55.                  * a zero value to terminate. */
  56. {
  57.     va_list arg2;
  58.     int count, i;
  59.     register char **array;
  60.  
  61.     arg2 = *args;
  62.     for (count = 1; va_arg(arg2, char *) != 0; count++) {
  63.     /* Null loop body. */
  64.     }
  65.     array = (char **) malloc((unsigned) (count * sizeof(char *)));
  66.     for (i = 0; i < count; i++) {
  67.     array[i] = va_arg(*args, char *);
  68.     }
  69.     return array;
  70. }
  71.